import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/display.css'
import scui from './scui'
import i18n from './locales'
import router from './router'
import store from './store'
import App from './App.vue'
import formCreate from '@form-create/element-ui'
import buttonPermission from '@/utils/buttonPermission'

import vue3SeamlessScroll from 'vue3-seamless-scroll'

// 解决 ElTable 自动宽度高度导致的「ResizeObserver loop limit exceeded」问题
const debounce = (fn, delay) => {
  let timer = null
  return function () {
    let context = this
    let args = arguments
    clearTimeout(timer)
    timer = setTimeout(function () {
      fn.apply(context, args)
    }, delay)
  }
}

const _ResizeObserver = window.ResizeObserver
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
  constructor(callback) {
    callback = debounce(callback, 16)
    super(callback)
  }
}

// 正式环境清除所有console.log
if (process.env.NODE_ENV === 'production') {
  if (window) {
    window.console.log = function () { }
  }
}

const app = createApp(App)
app.use(store)
app.use(router)
app.use(ElementPlus)
app.use(formCreate)
app.use(i18n)
app.use(scui)
app.use(buttonPermission)
app.use(vue3SeamlessScroll)

//挂载app
app.mount('#app')
